import type { TPrefabGroup } from '@/store/NFTCreator.store'
import axios from 'axios'

const app = axios.create()

app.defaults.baseURL = 'http://localhost:3306'

export default {
  async getConfig(): Promise<Config.InstanceGroup> {
    const res = await app.get('/config/fetch')

    return res.data
  },
  async resetConfig(): Promise<void> {
    const res = await app.get('/config/create')

    return res.data
  },
  async saveConfig(config: Config.InstanceGroup): Promise<void> {
    const res = await app.post('/config/update', config)
    return res.data
  },
  async getBase(): Promise<Base.dto> {
    const res = await app.get('/base/fetch')

    return res.data
  },
  async saveBase(config: Base.dto): Promise<void> {
    const res = await app.post('/base/update', config)
    return res.data
  },
  async saveData(id: number, data: TPrefabGroup[]): Promise<void> {
    await app.post('/data/save', {id, data})
  },
  async getDataById(id: number): Promise<TPrefabGroup[]> {
    const res = await app.get(`/data/fetch?id=${id}`)
    return res as unknown as TPrefabGroup[]
  },
  async savePrefabImage(data: FormData) {
    await app.post('/prefabImage/update', data)
  },
  async getPrefabImage() {
    const res = await app.get('/prefabImage/fetch')
    return res.data as unknown as any[]
  },
}
